package com.boonya.spring.beans;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName: Validation
 * @Description: TODO(功能说明 : 所有视图访问入口验证)
 * @author: pengjunlin
 * @motto: 学习需要毅力，那就秀毅力
 * @date 2021/3/28 10:33
 */
public class Validation extends AbstractController {

    private User user;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        String username = httpServletRequest.getParameter("username");
        String password = httpServletRequest.getParameter("password");
        if (username.equalsIgnoreCase(user.getUsername()) && password.equalsIgnoreCase(user.getPassword())) {
            return new ModelAndView("index");
        } else {
            return new ModelAndView("login");
        }
    }
}
